'------------------------- Overlay_Chart -------------------------------------------------
indiid++
if indicatorslistsel.item(indiid)="x" then

if lbar=1 then
Overlay_Chart
end if

barsback=bars '<--- can also be something like VAL(Overlay_Chartbarsbackedit.text)

if ibar>=lastbar-barsback then 
	
	defint incrov
    
    if overlaychartslist.itemcount>0 then

	if charttf(displayedfile)<=240 then
	indicolor(drawid)=blue '<--- replace with your color
	for incrov=1 to chartbars(Overlay_Chartbuffer(0)/7+1)		
	if replacesubstr$(Grid.Cell(Overlay_Chartbuffer(0) + 1 , incrov),"-",".")=replacesubstr$(Grid.Cell(rowgridoffset + 1 , ibar),"-",".") and Grid.Cell(Overlay_Chartbuffer(0) + 2 , incrov)=Grid.Cell(rowgridoffset + 2 , ibar) then    	
	.Data_Indi.Cell(drawid,lbar)=str$(val(Grid.Cell(Overlay_Chartbuffer(0) + 6 , incrov))*val(overlaychartsratiolist.item(0)))
	exit for
	'else
	'.Data_Indi.Cell(drawid,lbar)=.Data_Indi.Cell(drawid,lbar-1)
	'exit for
	end if
	next incrov
	end if
	
	if charttf(displayedfile)=1440 then
	indicolor(drawid)=blue '<--- replace with your color
	for incrov=1 to chartbars(Overlay_Chartbuffer(0)/7+1)	
	if replacesubstr$(Grid.Cell(Overlay_Chartbuffer(0) + 1 , incrov),"-",".")=replacesubstr$(Grid.Cell(rowgridoffset + 1 , ibar),"-",".") then    	
	.Data_Indi.Cell(drawid,lbar)=str$(val(Grid.Cell(Overlay_Chartbuffer(0) + 6 , incrov))*val(overlaychartsratiolist.item(0)))
	exit for
	'else	
	'if lbar<=1 then .Data_Indi.Cell(drawid,lbar)="0"
	'if lbar>1 then .Data_Indi.Cell(drawid,lbar)=.Data_Indi.Cell(drawid,lbar-1)
	'exit for
	end if
	next incrov
	end if

	if charttf(displayedfile)=10080 then
	indicolor(drawid)=blue '<--- replace with your color
	for incrov=1 to chartbars(Overlay_Chartbuffer(0)/7+1)

defstr yearov=mid$(Grid.Cell(Overlay_Chartbuffer(0) + 1 , incrov),1,4)
defstr monthov=mid$(Grid.Cell(Overlay_Chartbuffer(0) + 1 , incrov),6,2)
defstr dayov=mid$(Grid.Cell(Overlay_Chartbuffer(0) + 1 , incrov),9,2)
defstr dateov=yearov+";"+monthov+";"+dayov+";"+"00"+";"+"00"+";"+"00"
defstr unixtimeov=varptr$(date_to_unix_time(varptr(dateov)))

defstr year00=mid$(Grid.Cell(rowgridoffset + 1 , ibar),1,4)
defstr month00=mid$(Grid.Cell(rowgridoffset + 1 , ibar),6,2)
defstr day00=mid$(Grid.Cell(rowgridoffset + 1 , ibar),9,2)
defstr date00=year00+";"+month00+";"+day00+";"+"00"+";"+"00"+";"+"00"
defstr unixtime00=varptr$(date_to_unix_time(varptr(date00)))

	'if replacesubstr$(Grid.Cell(Overlay_Chartbuffer(0) + 1 , incrov),"-",".")=replacesubstr$(Grid.Cell(rowgridoffset + 1 , ibar),"-",".") then    	
if val(unixtimeov)>=val(unixtime00)-(1440*60*3) and val(unixtimeov)<val(unixtime00)+(1440*60*3) then
	.Data_Indi.Cell(drawid,lbar)=str$(val(Grid.Cell(Overlay_Chartbuffer(0) + 6 , incrov))*val(overlaychartsratiolist.item(0)))
	exit for
	'else	
	'if lbar<=1 then .Data_Indi.Cell(drawid,lbar)="0"
	'if lbar>1 then .Data_Indi.Cell(drawid,lbar)=.Data_Indi.Cell(drawid,lbar-1)
	'exit for
	end if
	next incrov
	end if

	if charttf(displayedfile)=43200 then
	indicolor(drawid)=blue '<--- replace with your color
	for incrov=1 to chartbars(Overlay_Chartbuffer(0)/7+1)	
	if MID$(replacesubstr$(Grid.Cell(Overlay_Chartbuffer(0) + 1 , incrov),"-",".") , 1 , 7)=MID$(replacesubstr$(Grid.Cell(rowgridoffset + 1 , ibar),"-",".") , 1 , 7) then    	
	.Data_Indi.Cell(drawid,lbar)=str$(val(Grid.Cell(Overlay_Chartbuffer(0) + 6 , incrov))*val(overlaychartsratiolist.item(0)))
	exit for
	'else	
	'if lbar<=1 then .Data_Indi.Cell(drawid,lbar)="0"
	'if lbar>1 then .Data_Indi.Cell(drawid,lbar)=.Data_Indi.Cell(drawid,lbar-1)
	'exit for
	end if
	next incrov
	end if

    drawid=drawid+2
    
    end if
    
    if overlaychartslist.itemcount>1 then
    
    if charttf(displayedfile)<=240 then
    indicolor(drawid)=green '<--- replace with your color
    for incrov=1 to chartbars(Overlay_Chartbuffer(1)/7+1)       
    if replacesubstr$(Grid.Cell(Overlay_Chartbuffer(1) + 1 , incrov),"-",".")=replacesubstr$(Grid.Cell(rowgridoffset + 1 , ibar),"-",".") and Grid.Cell(Overlay_Chartbuffer(1) + 2 , incrov)=Grid.Cell(rowgridoffset + 2 , ibar) then       
    .Data_Indi.Cell(drawid,lbar)=str$(val(Grid.Cell(Overlay_Chartbuffer(1) + 6 , incrov))*val(overlaychartsratiolist.item(1)))
    exit for
    'else
    '.Data_Indi.Cell(drawid,lbar)=.Data_Indi.Cell(drawid,lbar-1)
    'exit for
    end if
    next incrov
    end if
    
    if charttf(displayedfile)=1440 then
    indicolor(drawid)=green '<--- replace with your color
    for incrov=1 to chartbars(Overlay_Chartbuffer(1)/7+1)   
    if replacesubstr$(Grid.Cell(Overlay_Chartbuffer(1) + 1 , incrov),"-",".")=replacesubstr$(Grid.Cell(rowgridoffset + 1 , ibar),"-",".") then      
    .Data_Indi.Cell(drawid,lbar)=str$(val(Grid.Cell(Overlay_Chartbuffer(1) + 6 , incrov))*val(overlaychartsratiolist.item(1)))
    exit for
    'else   
    'if lbar<=1 then .Data_Indi.Cell(drawid,lbar)="0"
    'if lbar>1 then .Data_Indi.Cell(drawid,lbar)=.Data_Indi.Cell(drawid,lbar-1)
    'exit for
    end if
    next incrov
    end if

if charttf(displayedfile)=10080 then
	indicolor(drawid)=green '<--- replace with your color
	for incrov=1 to chartbars(Overlay_Chartbuffer(1)/7+1)

 yearov=mid$(Grid.Cell(Overlay_Chartbuffer(1) + 1 , incrov),1,4)
 monthov=mid$(Grid.Cell(Overlay_Chartbuffer(1) + 1 , incrov),6,2)
 dayov=mid$(Grid.Cell(Overlay_Chartbuffer(1) + 1 , incrov),9,2)
 dateov=yearov+";"+monthov+";"+dayov+";"+"00"+";"+"00"+";"+"00"
 unixtimeov=varptr$(date_to_unix_time(varptr(dateov)))

 year00=mid$(Grid.Cell(rowgridoffset + 1 , ibar),1,4)
 month00=mid$(Grid.Cell(rowgridoffset + 1 , ibar),6,2)
 day00=mid$(Grid.Cell(rowgridoffset + 1 , ibar),9,2)
 date00=year00+";"+month00+";"+day00+";"+"00"+";"+"00"+";"+"00"
 unixtime00=varptr$(date_to_unix_time(varptr(date00)))

	'if replacesubstr$(Grid.Cell(Overlay_Chartbuffer(1) + 1 , incrov),"-",".")=replacesubstr$(Grid.Cell(rowgridoffset + 1 , ibar),"-",".") then    	
if val(unixtimeov)>=val(unixtime00)-(1440*60*3) and val(unixtimeov)<val(unixtime00)+(1440*60*3) then
	.Data_Indi.Cell(drawid,lbar)=str$(val(Grid.Cell(Overlay_Chartbuffer(1) + 6 , incrov))*val(overlaychartsratiolist.item(1)))
	exit for
	'else	
	'if lbar<=1 then .Data_Indi.Cell(drawid,lbar)="0"
	'if lbar>1 then .Data_Indi.Cell(drawid,lbar)=.Data_Indi.Cell(drawid,lbar-1)
	'exit for
	end if
	next incrov
	end if

    if charttf(displayedfile)=43200 then
	indicolor(drawid)=green '<--- replace with your color
	for incrov=1 to chartbars(Overlay_Chartbuffer(1)/7+1)	
	if MID$(replacesubstr$(Grid.Cell(Overlay_Chartbuffer(1) + 1 , incrov),"-",".") , 1 , 7)=MID$(replacesubstr$(Grid.Cell(rowgridoffset + 1 , ibar),"-",".") , 1 , 7) then    	
	.Data_Indi.Cell(drawid,lbar)=str$(val(Grid.Cell(Overlay_Chartbuffer(1) + 6 , incrov))*val(overlaychartsratiolist.item(1)))
	exit for
	'else	
	'if lbar<=1 then .Data_Indi.Cell(drawid,lbar)="0"
	'if lbar>1 then .Data_Indi.Cell(drawid,lbar)=.Data_Indi.Cell(drawid,lbar-1)
	'exit for
	end if
	next incrov
	end if

    drawid=drawid+2
    
    end if
    
    if overlaychartslist.itemcount>2 then
    
    if charttf(displayedfile)<=240 then
    indicolor(drawid)=red '<--- replace with your color
    for incrov=1 to chartbars(Overlay_Chartbuffer(2)/7+1)       
    if replacesubstr$(Grid.Cell(Overlay_Chartbuffer(2) + 1 , incrov),"-",".")=replacesubstr$(Grid.Cell(rowgridoffset + 1 , ibar),"-",".") and Grid.Cell(Overlay_Chartbuffer(2) + 2 , incrov)=Grid.Cell(rowgridoffset + 2 , ibar) then       
    .Data_Indi.Cell(drawid,lbar)=str$(val(Grid.Cell(Overlay_Chartbuffer(2) + 6 , incrov))*val(overlaychartsratiolist.item(2)))
    exit for
    'else
    '.Data_Indi.Cell(drawid,lbar)=.Data_Indi.Cell(drawid,lbar-1)
    'exit for
    end if
    next incrov
    end if
    
    if charttf(displayedfile)=1440 then
    indicolor(drawid)=red '<--- replace with your color
    for incrov=1 to chartbars(Overlay_Chartbuffer(2)/7+1)   
    if replacesubstr$(Grid.Cell(Overlay_Chartbuffer(2) + 1 , incrov),"-",".")=replacesubstr$(Grid.Cell(rowgridoffset + 1 , ibar),"-",".") then      
    .Data_Indi.Cell(drawid,lbar)=str$(val(Grid.Cell(Overlay_Chartbuffer(2) + 6 , incrov))*val(overlaychartsratiolist.item(2)))
    exit for
    'else   
    'if lbar<=1 then .Data_Indi.Cell(drawid,lbar)="0"
    'if lbar>1 then .Data_Indi.Cell(drawid,lbar)=.Data_Indi.Cell(drawid,lbar-1)
    'exit for
    end if
    next incrov
    end if

    if charttf(displayedfile)=10080 then
	indicolor(drawid)=red '<--- replace with your color
	for incrov=1 to chartbars(Overlay_Chartbuffer(2)/7+1)

 yearov=mid$(Grid.Cell(Overlay_Chartbuffer(2) + 1 , incrov),1,4)
 monthov=mid$(Grid.Cell(Overlay_Chartbuffer(2) + 1 , incrov),6,2)
 dayov=mid$(Grid.Cell(Overlay_Chartbuffer(2) + 1 , incrov),9,2)
 dateov=yearov+";"+monthov+";"+dayov+";"+"00"+";"+"00"+";"+"00"
 unixtimeov=varptr$(date_to_unix_time(varptr(dateov)))

 year00=mid$(Grid.Cell(rowgridoffset + 1 , ibar),1,4)
 month00=mid$(Grid.Cell(rowgridoffset + 1 , ibar),6,2)
 day00=mid$(Grid.Cell(rowgridoffset + 1 , ibar),9,2)
 date00=year00+";"+month00+";"+day00+";"+"00"+";"+"00"+";"+"00"
 unixtime00=varptr$(date_to_unix_time(varptr(date00)))

	'if replacesubstr$(Grid.Cell(Overlay_Chartbuffer(2) + 1 , incrov),"-",".")=replacesubstr$(Grid.Cell(rowgridoffset + 1 , ibar),"-",".") then    	
if val(unixtimeov)>=val(unixtime00)-(1440*60*3) and val(unixtimeov)<val(unixtime00)+(1440*60*3) then
	.Data_Indi.Cell(drawid,lbar)=str$(val(Grid.Cell(Overlay_Chartbuffer(2) + 6 , incrov))*val(overlaychartsratiolist.item(2)))
	exit for
	'else	
	'if lbar<=1 then .Data_Indi.Cell(drawid,lbar)="0"
	'if lbar>1 then .Data_Indi.Cell(drawid,lbar)=.Data_Indi.Cell(drawid,lbar-1)
	'exit for
	end if
	next incrov
	end if
    
    if charttf(displayedfile)=43200 then
    indicolor(drawid)=red '<--- replace with your color
    for incrov=1 to chartbars(Overlay_Chartbuffer(2)/7+1)   
    if MID$(replacesubstr$(Grid.Cell(Overlay_Chartbuffer(2) + 1 , incrov),"-",".") , 1 , 7)=MID$(replacesubstr$(Grid.Cell(rowgridoffset + 1 , ibar),"-",".") , 1 , 7) then      
    .Data_Indi.Cell(drawid,lbar)=str$(val(Grid.Cell(Overlay_Chartbuffer(2) + 6 , incrov))*val(overlaychartsratiolist.item(2)))
    exit for
    'else   
    'if lbar<=1 then .Data_Indi.Cell(drawid,lbar)="0"
    'if lbar>1 then .Data_Indi.Cell(drawid,lbar)=.Data_Indi.Cell(drawid,lbar-1)
    'exit for
    end if
    next incrov
    end if

drawid=drawid+2    

    end if
    
    if overlaychartslist.itemcount>3 then
    
    if charttf(displayedfile)<=240 then
    indicolor(drawid)=brown '<--- replace with your color
    for incrov=1 to chartbars(Overlay_Chartbuffer(3)/7+1)       
    if replacesubstr$(Grid.Cell(Overlay_Chartbuffer(3) + 1 , incrov),"-",".")=replacesubstr$(Grid.Cell(rowgridoffset + 1 , ibar),"-",".") and Grid.Cell(Overlay_Chartbuffer(3) + 2 , incrov)=Grid.Cell(rowgridoffset + 2 , ibar) then       
    .Data_Indi.Cell(drawid,lbar)=str$(val(Grid.Cell(Overlay_Chartbuffer(3) + 6 , incrov))*val(overlaychartsratiolist.item(3)))
    exit for
    'else
    '.Data_Indi.Cell(drawid,lbar)=.Data_Indi.Cell(drawid,lbar-1)
    'exit for
    end if
    next incrov
    end if
    
    if charttf(displayedfile)=1440 then
    indicolor(drawid)=brown '<--- replace with your color
    for incrov=1 to chartbars(Overlay_Chartbuffer(3)/7+1)   
    if replacesubstr$(Grid.Cell(Overlay_Chartbuffer(3) + 1 , incrov),"-",".")=replacesubstr$(Grid.Cell(rowgridoffset + 1 , ibar),"-",".") then      
    .Data_Indi.Cell(drawid,lbar)=str$(val(Grid.Cell(Overlay_Chartbuffer(3) + 6 , incrov))*val(overlaychartsratiolist.item(3)))
    exit for
    'else   
    'if lbar<=1 then .Data_Indi.Cell(drawid,lbar)="0"
    'if lbar>1 then .Data_Indi.Cell(drawid,lbar)=.Data_Indi.Cell(drawid,lbar-1)
    'exit for
    end if
    next incrov
    end if

if charttf(displayedfile)=10080 then
	indicolor(drawid)=brown '<--- replace with your color
	for incrov=1 to chartbars(Overlay_Chartbuffer(3)/7+1)

 yearov=mid$(Grid.Cell(Overlay_Chartbuffer(3) + 1 , incrov),1,4)
 monthov=mid$(Grid.Cell(Overlay_Chartbuffer(3) + 1 , incrov),6,2)
 dayov=mid$(Grid.Cell(Overlay_Chartbuffer(3) + 1 , incrov),9,2)
 dateov=yearov+";"+monthov+";"+dayov+";"+"00"+";"+"00"+";"+"00"
 unixtimeov=varptr$(date_to_unix_time(varptr(dateov)))

 year00=mid$(Grid.Cell(rowgridoffset + 1 , ibar),1,4)
 month00=mid$(Grid.Cell(rowgridoffset + 1 , ibar),6,2)
 day00=mid$(Grid.Cell(rowgridoffset + 1 , ibar),9,2)
 date00=year00+";"+month00+";"+day00+";"+"00"+";"+"00"+";"+"00"
 unixtime00=varptr$(date_to_unix_time(varptr(date00)))

	'if replacesubstr$(Grid.Cell(Overlay_Chartbuffer(3) + 1 , incrov),"-",".")=replacesubstr$(Grid.Cell(rowgridoffset + 1 , ibar),"-",".") then    	
if val(unixtimeov)>=val(unixtime00)-(1440*60*3) and val(unixtimeov)<val(unixtime00)+(1440*60*3) then
	.Data_Indi.Cell(drawid,lbar)=str$(val(Grid.Cell(Overlay_Chartbuffer(3) + 6 , incrov))*val(overlaychartsratiolist.item(3)))
	exit for
	'else	
	'if lbar<=1 then .Data_Indi.Cell(drawid,lbar)="0"
	'if lbar>1 then .Data_Indi.Cell(drawid,lbar)=.Data_Indi.Cell(drawid,lbar-1)
	'exit for
	end if
	next incrov
	end if
    
    if charttf(displayedfile)=43200 then
    indicolor(drawid)=brown '<--- replace with your color
    for incrov=1 to chartbars(Overlay_Chartbuffer(3)/7+1)   
    if MID$(replacesubstr$(Grid.Cell(Overlay_Chartbuffer(3) + 1 , incrov),"-",".") , 1 , 7)=MID$(replacesubstr$(Grid.Cell(rowgridoffset + 1 , ibar),"-",".") , 1 , 7) then      
    .Data_Indi.Cell(drawid,lbar)=str$(val(Grid.Cell(Overlay_Chartbuffer(3) + 6 , incrov))*val(overlaychartsratiolist.item(3)))
    exit for
    'else   
    'if lbar<=1 then .Data_Indi.Cell(drawid,lbar)="0"
    'if lbar>1 then .Data_Indi.Cell(drawid,lbar)=.Data_Indi.Cell(drawid,lbar-1)
    'exit for
    end if
    next incrov
    end if

    drawid=drawid+2
    
    end if
    
    if overlaychartslist.itemcount>4 then
    
    if charttf(displayedfile)<=240 then
    indicolor(drawid)=yellow '<--- replace with your color
    for incrov=1 to chartbars(Overlay_Chartbuffer(4)/7+1)       
    if replacesubstr$(Grid.Cell(Overlay_Chartbuffer(4) + 1 , incrov),"-",".")=replacesubstr$(Grid.Cell(rowgridoffset + 1 , ibar),"-",".") and Grid.Cell(Overlay_Chartbuffer(4) + 2 , incrov)=Grid.Cell(rowgridoffset + 2 , ibar) then       
    .Data_Indi.Cell(drawid,lbar)=str$(val(Grid.Cell(Overlay_Chartbuffer(4) + 6 , incrov))*val(overlaychartsratiolist.item(4)))
    exit for
    'else
    '.Data_Indi.Cell(drawid,lbar)=.Data_Indi.Cell(drawid,lbar-1)
    'exit for
    end if
    next incrov
    end if
    
    if charttf(displayedfile)=1440 then
    indicolor(drawid)=yellow '<--- replace with your color
    for incrov=1 to chartbars(Overlay_Chartbuffer(4)/7+1)   
    if replacesubstr$(Grid.Cell(Overlay_Chartbuffer(4) + 1 , incrov),"-",".")=replacesubstr$(Grid.Cell(rowgridoffset + 1 , ibar),"-",".") then      
    .Data_Indi.Cell(drawid,lbar)=str$(val(Grid.Cell(Overlay_Chartbuffer(4) + 6 , incrov))*val(overlaychartsratiolist.item(4)))
    exit for
    'else   
    'if lbar<=1 then .Data_Indi.Cell(drawid,lbar)="0"
    'if lbar>1 then .Data_Indi.Cell(drawid,lbar)=.Data_Indi.Cell(drawid,lbar-1)
    'exit for
    end if
    next incrov
    end if

if charttf(displayedfile)=10080 then
	indicolor(drawid)=yellow '<--- replace with your color
	for incrov=1 to chartbars(Overlay_Chartbuffer(4)/7+1)

 yearov=mid$(Grid.Cell(Overlay_Chartbuffer(4) + 1 , incrov),1,4)
 monthov=mid$(Grid.Cell(Overlay_Chartbuffer(4) + 1 , incrov),6,2)
 dayov=mid$(Grid.Cell(Overlay_Chartbuffer(4) + 1 , incrov),9,2)
 dateov=yearov+";"+monthov+";"+dayov+";"+"00"+";"+"00"+";"+"00"
 unixtimeov=varptr$(date_to_unix_time(varptr(dateov)))

 year00=mid$(Grid.Cell(rowgridoffset + 1 , ibar),1,4)
 month00=mid$(Grid.Cell(rowgridoffset + 1 , ibar),6,2)
 day00=mid$(Grid.Cell(rowgridoffset + 1 , ibar),9,2)
 date00=year00+";"+month00+";"+day00+";"+"00"+";"+"00"+";"+"00"
 unixtime00=varptr$(date_to_unix_time(varptr(date00)))

	'if replacesubstr$(Grid.Cell(Overlay_Chartbuffer(4) + 1 , incrov),"-",".")=replacesubstr$(Grid.Cell(rowgridoffset + 1 , ibar),"-",".") then    	
if val(unixtimeov)>=val(unixtime00)-(1440*60*3) and val(unixtimeov)<val(unixtime00)+(1440*60*3) then
	.Data_Indi.Cell(drawid,lbar)=str$(val(Grid.Cell(Overlay_Chartbuffer(4) + 6 , incrov))*val(overlaychartsratiolist.item(4)))
	exit for
	'else	
	'if lbar<=1 then .Data_Indi.Cell(drawid,lbar)="0"
	'if lbar>1 then .Data_Indi.Cell(drawid,lbar)=.Data_Indi.Cell(drawid,lbar-1)
	'exit for
	end if
	next incrov
	end if
    
    if charttf(displayedfile)=43200 then
    indicolor(drawid)=yellow '<--- replace with your color
    for incrov=1 to chartbars(Overlay_Chartbuffer(4)/7+1)   
    if MID$(replacesubstr$(Grid.Cell(Overlay_Chartbuffer(4) + 1 , incrov),"-",".") , 1 , 7)=MID$(replacesubstr$(Grid.Cell(rowgridoffset + 1 , ibar),"-",".") , 1 , 7) then      
    .Data_Indi.Cell(drawid,lbar)=str$(val(Grid.Cell(Overlay_Chartbuffer(4) + 6 , incrov))*val(overlaychartsratiolist.item(4)))
    exit for
    'else   
    'if lbar<=1 then .Data_Indi.Cell(drawid,lbar)="0"
    'if lbar>1 then .Data_Indi.Cell(drawid,lbar)=.Data_Indi.Cell(drawid,lbar-1)
    'exit for
    end if
    next incrov
    end if

    drawid=drawid+2
    
    end if
    
    if overlaychartslist.itemcount>5 then
    
    if charttf(displayedfile)<=240 then
    indicolor(drawid)=orange '<--- replace with your color
    for incrov=1 to chartbars(Overlay_Chartbuffer(5)/7+1)       
    if replacesubstr$(Grid.Cell(Overlay_Chartbuffer(5) + 1 , incrov),"-",".")=replacesubstr$(Grid.Cell(rowgridoffset + 1 , ibar),"-",".") and Grid.Cell(Overlay_Chartbuffer(5) + 2 , incrov)=Grid.Cell(rowgridoffset + 2 , ibar) then       
    .Data_Indi.Cell(drawid,lbar)=str$(val(Grid.Cell(Overlay_Chartbuffer(5) + 6 , incrov))*val(overlaychartsratiolist.item(5)))
    exit for
    'else
    '.Data_Indi.Cell(drawid,lbar)=.Data_Indi.Cell(drawid,lbar-1)
    'exit for
    end if
    next incrov
    end if
    
    if charttf(displayedfile)=1440 then
    indicolor(drawid)=orange '<--- replace with your color
    for incrov=1 to chartbars(Overlay_Chartbuffer(5)/7+1)   
    if replacesubstr$(Grid.Cell(Overlay_Chartbuffer(5) + 1 , incrov),"-",".")=replacesubstr$(Grid.Cell(rowgridoffset + 1 , ibar),"-",".") then      
    .Data_Indi.Cell(drawid,lbar)=str$(val(Grid.Cell(Overlay_Chartbuffer(5) + 6 , incrov))*val(overlaychartsratiolist.item(5)))
    exit for
    'else   
    'if lbar<=1 then .Data_Indi.Cell(drawid,lbar)="0"
    'if lbar>1 then .Data_Indi.Cell(drawid,lbar)=.Data_Indi.Cell(drawid,lbar-1)
    'exit for
    end if
    next incrov
    end if

if charttf(displayedfile)=10080 then
	indicolor(drawid)=orange '<--- replace with your color
	for incrov=1 to chartbars(Overlay_Chartbuffer(5)/7+1)

 yearov=mid$(Grid.Cell(Overlay_Chartbuffer(5) + 1 , incrov),1,4)
 monthov=mid$(Grid.Cell(Overlay_Chartbuffer(5) + 1 , incrov),6,2)
 dayov=mid$(Grid.Cell(Overlay_Chartbuffer(5) + 1 , incrov),9,2)
 dateov=yearov+";"+monthov+";"+dayov+";"+"00"+";"+"00"+";"+"00"
 unixtimeov=varptr$(date_to_unix_time(varptr(dateov)))

 year00=mid$(Grid.Cell(rowgridoffset + 1 , ibar),1,4)
 month00=mid$(Grid.Cell(rowgridoffset + 1 , ibar),6,2)
 day00=mid$(Grid.Cell(rowgridoffset + 1 , ibar),9,2)
 date00=year00+";"+month00+";"+day00+";"+"00"+";"+"00"+";"+"00"
 unixtime00=varptr$(date_to_unix_time(varptr(date00)))

	'if replacesubstr$(Grid.Cell(Overlay_Chartbuffer(5) + 1 , incrov),"-",".")=replacesubstr$(Grid.Cell(rowgridoffset + 1 , ibar),"-",".") then    	
if val(unixtimeov)>=val(unixtime00)-(1440*60*3) and val(unixtimeov)<val(unixtime00)+(1440*60*3) then
	.Data_Indi.Cell(drawid,lbar)=str$(val(Grid.Cell(Overlay_Chartbuffer(5) + 6 , incrov))*val(overlaychartsratiolist.item(5)))
	exit for
	'else	
	'if lbar<=1 then .Data_Indi.Cell(drawid,lbar)="0"
	'if lbar>1 then .Data_Indi.Cell(drawid,lbar)=.Data_Indi.Cell(drawid,lbar-1)
	'exit for
	end if
	next incrov
	end if
    
    if charttf(displayedfile)=43200 then
    indicolor(drawid)=orange '<--- replace with your color
    for incrov=1 to chartbars(Overlay_Chartbuffer(5)/7+1)   
    if MID$(replacesubstr$(Grid.Cell(Overlay_Chartbuffer(5) + 1 , incrov),"-",".") , 1 , 7)=MID$(replacesubstr$(Grid.Cell(rowgridoffset + 1 , ibar),"-",".") , 1 , 7) then      
    .Data_Indi.Cell(drawid,lbar)=str$(val(Grid.Cell(Overlay_Chartbuffer(5) + 6 , incrov))*val(overlaychartsratiolist.item(5)))
    exit for
    'else   
    'if lbar<=1 then .Data_Indi.Cell(drawid,lbar)="0"
    'if lbar>1 then .Data_Indi.Cell(drawid,lbar)=.Data_Indi.Cell(drawid,lbar-1)
    'exit for
    end if
    next incrov
    end if

    drawid=drawid+2
    
    end if
    
    if overlaychartslist.itemcount>6 then
    
    if charttf(displayedfile)<=240 then
    indicolor(drawid)=purple '<--- replace with your color
    for incrov=1 to chartbars(Overlay_Chartbuffer(6)/7+1)       
    if replacesubstr$(Grid.Cell(Overlay_Chartbuffer(6) + 1 , incrov),"-",".")=replacesubstr$(Grid.Cell(rowgridoffset + 1 , ibar),"-",".") and Grid.Cell(Overlay_Chartbuffer(6) + 2 , incrov)=Grid.Cell(rowgridoffset + 2 , ibar) then       
    .Data_Indi.Cell(drawid,lbar)=str$(val(Grid.Cell(Overlay_Chartbuffer(6) + 6 , incrov))*val(overlaychartsratiolist.item(6)))
    exit for
    'else
    '.Data_Indi.Cell(drawid,lbar)=.Data_Indi.Cell(drawid,lbar-1)
    'exit for
    end if
    next incrov
    end if
    
    if charttf(displayedfile)=1440 then
    indicolor(drawid)=purple '<--- replace with your color
    for incrov=1 to chartbars(Overlay_Chartbuffer(6)/7+1)   
    if replacesubstr$(Grid.Cell(Overlay_Chartbuffer(6) + 1 , incrov),"-",".")=replacesubstr$(Grid.Cell(rowgridoffset + 1 , ibar),"-",".") then      
    .Data_Indi.Cell(drawid,lbar)=str$(val(Grid.Cell(Overlay_Chartbuffer(6) + 6 , incrov))*val(overlaychartsratiolist.item(6)))
    exit for
    'else   
    'if lbar<=1 then .Data_Indi.Cell(drawid,lbar)="0"
    'if lbar>1 then .Data_Indi.Cell(drawid,lbar)=.Data_Indi.Cell(drawid,lbar-1)
    'exit for
    end if
    next incrov
    end if

if charttf(displayedfile)=10080 then
	indicolor(drawid)=purple '<--- replace with your color
	for incrov=1 to chartbars(Overlay_Chartbuffer(6)/7+1)

 yearov=mid$(Grid.Cell(Overlay_Chartbuffer(6) + 1 , incrov),1,4)
 monthov=mid$(Grid.Cell(Overlay_Chartbuffer(6) + 1 , incrov),6,2)
 dayov=mid$(Grid.Cell(Overlay_Chartbuffer(6) + 1 , incrov),9,2)
 dateov=yearov+";"+monthov+";"+dayov+";"+"00"+";"+"00"+";"+"00"
 unixtimeov=varptr$(date_to_unix_time(varptr(dateov)))

 year00=mid$(Grid.Cell(rowgridoffset + 1 , ibar),1,4)
 month00=mid$(Grid.Cell(rowgridoffset + 1 , ibar),6,2)
 day00=mid$(Grid.Cell(rowgridoffset + 1 , ibar),9,2)
 date00=year00+";"+month00+";"+day00+";"+"00"+";"+"00"+";"+"00"
 unixtime00=varptr$(date_to_unix_time(varptr(date00)))

	'if replacesubstr$(Grid.Cell(Overlay_Chartbuffer(6) + 1 , incrov),"-",".")=replacesubstr$(Grid.Cell(rowgridoffset + 1 , ibar),"-",".") then    	
if val(unixtimeov)>=val(unixtime00)-(1440*60*3) and val(unixtimeov)<val(unixtime00)+(1440*60*3) then
	.Data_Indi.Cell(drawid,lbar)=str$(val(Grid.Cell(Overlay_Chartbuffer(6) + 6 , incrov))*val(overlaychartsratiolist.item(6)))
	exit for
	'else	
	'if lbar<=1 then .Data_Indi.Cell(drawid,lbar)="0"
	'if lbar>1 then .Data_Indi.Cell(drawid,lbar)=.Data_Indi.Cell(drawid,lbar-1)
	'exit for
	end if
	next incrov
	end if
    
    if charttf(displayedfile)=43200 then
    indicolor(drawid)=purple '<--- replace with your color
    for incrov=1 to chartbars(Overlay_Chartbuffer(6)/7+1)   
    if MID$(replacesubstr$(Grid.Cell(Overlay_Chartbuffer(6) + 1 , incrov),"-",".") , 1 , 7)=MID$(replacesubstr$(Grid.Cell(rowgridoffset + 1 , ibar),"-",".") , 1 , 7) then      
    .Data_Indi.Cell(drawid,lbar)=str$(val(Grid.Cell(Overlay_Chartbuffer(6) + 6 , incrov))*val(overlaychartsratiolist.item(6)))
    exit for
    'else   
    'if lbar<=1 then .Data_Indi.Cell(drawid,lbar)="0"
    'if lbar>1 then .Data_Indi.Cell(drawid,lbar)=.Data_Indi.Cell(drawid,lbar-1)
    'exit for
    end if
    next incrov
    end if

    drawid=drawid+2
    
    end if
    
    if overlaychartslist.itemcount>7 then
    
    if charttf(displayedfile)<=240 then
    indicolor(drawid)=gray '<--- replace with your color
    for incrov=1 to chartbars(Overlay_Chartbuffer(7)/7+1)       
    if replacesubstr$(Grid.Cell(Overlay_Chartbuffer(7) + 1 , incrov),"-",".")=replacesubstr$(Grid.Cell(rowgridoffset + 1 , ibar),"-",".") and Grid.Cell(Overlay_Chartbuffer(7) + 2 , incrov)=Grid.Cell(rowgridoffset + 2 , ibar) then       
    .Data_Indi.Cell(drawid,lbar)=str$(val(Grid.Cell(Overlay_Chartbuffer(7) + 6 , incrov))*val(overlaychartsratiolist.item(7)))
    exit for
    'else
    '.Data_Indi.Cell(drawid,lbar)=.Data_Indi.Cell(drawid,lbar-1)
    'exit for
    end if
    next incrov
    end if
    
    if charttf(displayedfile)=1440 then
    indicolor(drawid)=gray '<--- replace with your color
    for incrov=1 to chartbars(Overlay_Chartbuffer(7)/7+1)   
    if replacesubstr$(Grid.Cell(Overlay_Chartbuffer(7) + 1 , incrov),"-",".")=replacesubstr$(Grid.Cell(rowgridoffset + 1 , ibar),"-",".") then      
    .Data_Indi.Cell(drawid,lbar)=str$(val(Grid.Cell(Overlay_Chartbuffer(7) + 6 , incrov))*val(overlaychartsratiolist.item(7)))
    exit for
    'else   
    'if lbar<=1 then .Data_Indi.Cell(drawid,lbar)="0"
    'if lbar>1 then .Data_Indi.Cell(drawid,lbar)=.Data_Indi.Cell(drawid,lbar-1)
    'exit for
    end if
    next incrov
    end if

if charttf(displayedfile)=10080 then
	indicolor(drawid)=gray '<--- replace with your color
	for incrov=1 to chartbars(Overlay_Chartbuffer(7)/7+1)

 yearov=mid$(Grid.Cell(Overlay_Chartbuffer(7) + 1 , incrov),1,4)
 monthov=mid$(Grid.Cell(Overlay_Chartbuffer(7) + 1 , incrov),6,2)
 dayov=mid$(Grid.Cell(Overlay_Chartbuffer(7) + 1 , incrov),9,2)
 dateov=yearov+";"+monthov+";"+dayov+";"+"00"+";"+"00"+";"+"00"
 unixtimeov=varptr$(date_to_unix_time(varptr(dateov)))

 year00=mid$(Grid.Cell(rowgridoffset + 1 , ibar),1,4)
 month00=mid$(Grid.Cell(rowgridoffset + 1 , ibar),6,2)
 day00=mid$(Grid.Cell(rowgridoffset + 1 , ibar),9,2)
 date00=year00+";"+month00+";"+day00+";"+"00"+";"+"00"+";"+"00"
 unixtime00=varptr$(date_to_unix_time(varptr(date00)))

	'if replacesubstr$(Grid.Cell(Overlay_Chartbuffer(7) + 1 , incrov),"-",".")=replacesubstr$(Grid.Cell(rowgridoffset + 1 , ibar),"-",".") then    	
if val(unixtimeov)>=val(unixtime00)-(1440*60*3) and val(unixtimeov)<val(unixtime00)+(1440*60*3) then
	.Data_Indi.Cell(drawid,lbar)=str$(val(Grid.Cell(Overlay_Chartbuffer(7) + 6 , incrov))*val(overlaychartsratiolist.item(7)))
	exit for
	'else	
	'if lbar<=1 then .Data_Indi.Cell(drawid,lbar)="0"
	'if lbar>1 then .Data_Indi.Cell(drawid,lbar)=.Data_Indi.Cell(drawid,lbar-1)
	'exit for
	end if
	next incrov
	end if
    
    if charttf(displayedfile)=43200 then
    indicolor(drawid)=gray '<--- replace with your color
    for incrov=1 to chartbars(Overlay_Chartbuffer(7)/7+1)   
    if MID$(replacesubstr$(Grid.Cell(Overlay_Chartbuffer(7) + 1 , incrov),"-",".") , 1 , 7)=MID$(replacesubstr$(Grid.Cell(rowgridoffset + 1 , ibar),"-",".") , 1 , 7) then      
    .Data_Indi.Cell(drawid,lbar)=str$(val(Grid.Cell(Overlay_Chartbuffer(7) + 6 , incrov))*val(overlaychartsratiolist.item(7)))
    exit for
    'else   
    'if lbar<=1 then .Data_Indi.Cell(drawid,lbar)="0"
    'if lbar>1 then .Data_Indi.Cell(drawid,lbar)=.Data_Indi.Cell(drawid,lbar-1)
    'exit for
    end if
    next incrov
    end if

    drawid=drawid+2
    
    end if
    
    'indicolor(drawid)=blue '<--- replace with your color
    '.Data_Indi.Cell(drawid,lbar)= str$(val(Grid.Cell(Overlay_Chartbuffer(1) + 6 , ibar))*val(overlaychartsratiolist.item(Overlay_Chartbuffer(1)/7)))
    'drawid=drawid+2

    'indicolor(drawid)=blue '<--- replace with your color
    '.Data_Indi.Cell(drawid,lbar)= str$(val(Grid.Cell(Overlay_Chartbuffer(2) + 6 , ibar))*val(overlaychartsratiolist.item(Overlay_Chartbuffer(2)/7)))
    'drawid=drawid+2
end if

end if
'------------------------- End Overlay_Chart -------------------------------------------------
